package edu.upf.opencities.web.manager.impl;

import edu.upf.opencities.datamodel.Service;
import edu.upf.opencities.datamodel.Services;
import edu.upf.opencities.datamodel.User;
import edu.upf.opencities.web.dao.impl.DAOImpl;
import edu.upf.opencities.web.manager.ServiceManager;
import edu.upf.opencities.web.manager.UserManager;

public class ManagerImpl implements ServiceManager, UserManager{
	
	private static ManagerImpl managerImpl = null;
	
	private DAOImpl dao = DAOImpl.getInstace();
	
	 public static synchronized ManagerImpl getInstace() {
	        if (null == managerImpl) {
	        	managerImpl = new ManagerImpl();
	        }
	        return managerImpl;
	    }

	//USER 
	 
	@Override
	public boolean registerUser(User user) {	
		return dao.registerUser(user);		
	}

	@Override
	public boolean userUpdate(User user) {
		return dao.userUpdate(user);
	}

	@Override
	public User getUser(User user) {
		return dao.getUser(user);
	}

	@Override
	public void deleteUser(User user) {
		dao.deleteUser(user);
	}

	@Override
	public boolean loginUser(User user) {	
		return dao.loginUser(user);
	}
	
	//SERVICE
	
    public Services getServices(String key, String value) {
        return dao.getServicesByProperty(key, value);
   }

   public Service getOneService(String serviceId) {
       return dao.getOneService(serviceId);
   }

	@Override
	public Service createNewService(Service service, User user) {	
		return dao.registerService(service, user);
	}

	public boolean updateService(Service service, User user) {
		return dao.updateService(service, user);
	}

	@Override
	public void deleteService(Service service, User user) {
		dao.deleteService(service,user);
	}

	@Override
	public void addTwitter(Service service, User user) {
		dao.addTwitter(service,user);
	}

}
